home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / cagd_lib / cagdcsrf.c < prev    next >
C/C++ Source or Header  |  1995-12-30  |  4KB  |  98 lines

  1. /******************************************************************************
  2. * CagdCSrf.c - Construct a surface using a set of curves.                     *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Sep. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /*****************************************************************************
  10. * DESCRIPTION:                                                               M
  11. * Constructs a surface using a set of curves. Curves are made to be         M
  12. * compatible and then each is substituted into the new surface's mesh as a   M
  13. * row.                                         M
  14. *   If the OtherOrder is less than the number of curves, number of curves is M
  15. * used.                                         M
  16. *   A knot vector is formed with uniform open end for the other direction,   M
  17. * so it interpolates the first and last curves.                         M
  18. *   Note, however, that only the first and the last curves are interpolated  M
  19. * if OtherOrder is greater than 2.                                           M
  20. *                                                                            *
  21. * PARAMETERS:                                                                M
  22. *   CrvList:      List of curves to consturct a surface with.                M
  23. *   OtherOrder:   Other order of surface.                     M
  24. *                                                                            *
  25. * RETURN VALUE:                                                              M
  26. *   CagdSrfStruct *:  Constructed surface from curves.                       M
  27. *                                                                            *
  28. * KEYWORDS:                                                                  M
  29. *   CagdSrfFromCrvs, surface constructors                                    M
  30. *****************************************************************************/
  31. CagdSrfStruct *CagdSrfFromCrvs(CagdCrvStruct *CrvList, int OtherOrder)
  32. {
  33.     CagdBType IsNotRational;
  34.     int i, j, NumCrvs, UOrder, VOrder, MaxCoord, Length;
  35.     CagdRType **SrfPoints;
  36.     CagdCrvStruct *Crv, **CrvVec;
  37.     CagdSrfStruct *Srf;
  38.  
  39.     /* Find out how many curves we have and put them in a linear vector.     */
  40.     /* Note the vector have a COPY of the curves so we can modify them.      */
  41.     for (NumCrvs = 0, Crv = CrvList;
  42.      Crv != NULL;
  43.      NumCrvs++, Crv = Crv -> Pnext);
  44.     CrvVec = (CagdCrvStruct **) IritMalloc(sizeof(CagdCrvStruct *) * NumCrvs);
  45.     for (i = 0, Crv = CrvList;
  46.      i < NumCrvs;
  47.      i++, Crv = Crv -> Pnext)
  48.     CrvVec[i] = CagdCrvCopy(Crv);
  49.  
  50.     /* Traverse vector in a O(n^2) fashion and make all curves compatible.   */
  51.     for (i = 0; i < NumCrvs - 1; i++)
  52.     for (j = i + 1; j < NumCrvs; j++)
  53.         CagdMakeCrvsCompatible(&CrvVec[i], &CrvVec[j], TRUE, TRUE);
  54.  
  55.     /* Construct the surface. All required information is now available.     */
  56.     UOrder = CrvVec[0] -> Order;
  57.     VOrder = MIN(NumCrvs, OtherOrder);
  58.     if (NumCrvs == VOrder && CrvVec[0] -> GType == CAGD_CBEZIER_TYPE) {
  59.         /* Allocate a bezier surface. */
  60.     Srf = BzrSrfNew(CrvVec[0] -> Length, NumCrvs, CrvVec[0] -> PType);
  61.     }
  62.     else {
  63.     /* Allocate a bspline surface. */
  64.     Srf = BspPeriodicSrfNew(CrvVec[0] -> Length, NumCrvs, UOrder, VOrder,
  65.                 CrvVec[0] -> Periodic, FALSE,
  66.                 CrvVec[0] -> PType);
  67.     IritFree((VoidPtr) Srf -> UKnotVector);
  68.     Srf -> UKnotVector = BspKnotCopy(CrvVec[0] -> KnotVector,
  69.                      CAGD_CRV_PT_LST_LEN(CrvVec[0]) +
  70.                      UOrder);
  71.     BspKnotUniformOpen(NumCrvs, VOrder, Srf -> VKnotVector);
  72.     }
  73.  
  74.     /* Substitute each curve as a row into the surface mesh and delete it. */
  75.     SrfPoints = Srf -> Points;
  76.     i = 0;
  77.     MaxCoord = CAGD_NUM_OF_PT_COORD(CrvVec[0] -> PType),
  78.     IsNotRational = !CAGD_IS_RATIONAL_CRV(CrvVec[0]);
  79.     Length = CrvVec[0] -> Length;
  80.  
  81.     for (j = 0; j < NumCrvs; j++) {
  82.     int k;
  83.     CagdRType
  84.         **CrvPoints = CrvVec[j] -> Points;
  85.  
  86.         for (k = IsNotRational; k <= MaxCoord; k++)
  87.         CAGD_GEN_COPY(&SrfPoints[k][i], CrvPoints[k],
  88.               sizeof(CagdRType) * Length);
  89.  
  90.     CagdCrvFree(CrvVec[j]);
  91.     i += Length;
  92.     }
  93.  
  94.     IritFree((VoidPtr) CrvVec);
  95.  
  96.     return Srf;
  97. }
  98.